const http = require("htpp");

//创建服务器
const server = http.createServer((request, response) => {
    console.log("method", request.method);  //请求方式 get/post
    console.log("url",request.url); //请求地址

    const {pathname, searchParams} = new URL(request.url, "http://127.0.0.1:8080");
    console.log("pathname", pathname);
    const username = searchParams.get("uesrname");
    const pwd = searchParams.get("pwd");
    console.log("username pwd", username, pwd);
    request.on("data",(buffer) => {
        console.log("请求体数据", buffer.toString());
    })

    response.statusCode = 201
    response.setHeader("Content-Type", "text/html;charset=utf-8")
    response.end("<h1 style='color:red;'>我是响应体</h1>")
})

server.listen(8080,() => {
    console.log("启动服务成功: http://127.0.0.1:8080");
})